package com.xieh.webmagic.magic;

import us.codecraft.webmagic.Page;
import us.codecraft.webmagic.Site;
import us.codecraft.webmagic.Spider;
import us.codecraft.webmagic.processor.PageProcessor;



/**
 * @author 谢辉
 * @Classname MyProcessor
 * @Description TODO
 * @Date 2020/11/20 15:52
 */
public class MyProcessor  implements PageProcessor {
    @Override
    public void process(Page page) {
        // 将爬取的网页源代码输出到控制台
        System.out.println(page.getHtml().toString());
    }

    @Override
    public Site getSite() {
        return Site.me().setSleepTime(100)
                .setRetryTimes(3)
                .setUserAgent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_2) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.65 Safari/537.31");
    }

    public static void main(String[] args) {
        Spider.create(new MyProcessor())
                .thread(5)
                .addUrl("https://blog.csdn.net/")
                .run();
    }
}
